<template>
  <el-container class="template-page">
    <el-header>
      <div class="left-panel">
		  <el-button type="danger" plain icon="el-icon-delete"  @click="batchDelete"></el-button>
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
          <el-input v-model="search.templateName" placeholder="关键词" clearable></el-input>
          <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <jdTable ref="table" :apiObj="apiObj" size="large" @selection-change="selectionChange" :params="params" stripe>
		<el-table-column type="selection"></el-table-column>
        <el-table-column label="手机号码" prop="tel" width="200"></el-table-column>
        <el-table-column label="通知内容" prop="sendContent" min-width="200" :show-overflow-tooltip="true"></el-table-column>
		<el-table-column label="发送渠道" prop="msgType" min-width="200" :show-overflow-tooltip="true">
			<template #default="scope">
				<DictTag :options="message_type" :value="scope.row.msgType"></DictTag>
			</template>
		</el-table-column>
		<el-table-column label="状态" prop="used" min-width="200" :show-overflow-tooltip="true">
			<template #default="scope">
				<DictTag :options="message_status" :value="scope.row.used"></DictTag>
			</template>
		</el-table-column>
		<el-table-column label="发送时间" prop="createTime" width="200"></el-table-column>
		<el-table-column label="备注" prop="otherText" min-width="200" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="200">
          <template #default="scope">
            <el-button-group>
              <el-popconfirm title="确定要删除吗？" @confirm="templateDelete(scope.row, scope.$index)">
                <template #reference>
                  <el-button text type="primary" class="button">删除</el-button>
                </template>
              </el-popconfirm>
            </el-button-group>
          </template>
        </el-table-column>
      </jdTable>
    </el-main>
  </el-container>


</template>

<script>

export default {
  components: {

  },
  data() {
    return {
      selection: [],
      search: {
        templateName: ""
      },
      apiObj: this.$API.system.msg.list,
      params: {},
      dialog: {
        save: false
      },
      message_type: [],
	  message_status:[],
    }
  },
  mounted() {
    this.getDict()
  },
  methods: {
    //删除
    async templateDelete(row) {
      var res = await this.$API.system.template.delTemplate.delete(row.id)
      if (res.code == 200) {
        this.$refs.table.refresh()
        this.$message.success("删除成功")
      } else {
        this.$alert(res.msg, "提示", { type: "error" })
      }
    },
    // 获取通知方式字典
    async getDict() {
      this.message_type = await this.Dict.get("sys_message_model")
	  this.message_status = await this.Dict.get("sys_msg_status")
    },
    // 搜索
    upsearch() {
      this.params = { ...this.search }
    },
    // 批量选择
    selectionChange(value) {
      this.selection = value
    },
    // 监听成功回调
    handleSaveSuccess() {
      this.$refs.table.refresh()
    },
	// 批量删除
	batchDelete(){
		this.$confirm(`确定删除选中的 ${this.selection.length} 项吗？`, "提示", {
			type: "warning"
		})
			.then(async () => {
				const loading = this.$loading()
				let ids = this.selection.map((item) => item.msgId)
				console.log(ids)
				loading.close()
			})
			.catch(() => {})
	}

  }
}
</script>

<style lang="scss" scoped></style>
